import os

try:
	from flask import Flask, render_template, request
except ImportError:
	os.system("pip install flask")
else:
	pass
finally:
	from flask import Flask, render_template, request


PROJ_ROOT = os.path.dirname(os.path.dirname(__file__))

app = Flask(
			__name__,
			static_folder=os.path.join('..',PROJ_ROOT, 'frontend', 'static'),
    		template_folder=os.path.join('..',PROJ_ROOT, 'frontend', 'templates'),
			static_url_path='/static',
			instance_relative_config=True
	)

@app.route('/', methods=['GET','POST'])
def view_index():
	return render_template('index.html')


@app.route("/login", methods=["GET","POST"])
def view_login():
	
	name = request.form.get('username')
	pwd = request.form.get('password')

	if bool(name) and bool(pwd):
		return render_template("index.html")
	else:
		return render_template("login.html")

if __name__ == '__main__':

	cfg = {
		"host": "0.0.0.0",
		"port": 5000,
		"debug": True
	}
	app.run(**cfg)